/**
 * 
 */
package com.magus.project.yddemo.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.magus.framework.core.repository.BaseRepository;
import com.magus.framework.core.service.BaseService;
import com.magus.project.yddemo.entity.IndicatorMapperData;
import com.magus.project.yddemo.repository.IndicatorMapperDataRepository;

/**
 * @author wenyu.han
 * @date 2018-03-19 15:03:30
 */

@Service
@Transactional(readOnly = true)
public class IndicatorMapperDataService extends BaseService<IndicatorMapperData, String> {

	@Autowired
	private IndicatorMapperDataRepository mapperDataRepository;

	@Override
	protected BaseRepository<IndicatorMapperData, String> getBaseRepository() {
		return mapperDataRepository;
	}

	public IndicatorMapperData findByIndicatorCodeAndTime(String indicatorCode, Long time) {
		IndicatorMapperData data = null;
		data = mapperDataRepository.findByIndicatorCodeAndTime(indicatorCode, time);
		if (data == null) {
			data = new IndicatorMapperData();
			data.setValue(0.0);
			data.setTime(time);
			data.setIndicatorCode(indicatorCode);
		}
		return data;
	}

	public List<IndicatorMapperData> findByIndicatorCodeAndTimeGreaterThanEqualAndTimeLessThanEqual(
			String indicatorCode, Long beginTime, Long endTime) {

		return mapperDataRepository.findByIndicatorCodeAndTimeGreaterThanEqualAndTimeLessThanEqual(indicatorCode,
				beginTime, endTime);
	}
}
